<?php

declare (strict_types = 1);

namespace auth\contract;

interface UserProvider
{
    /**
     * 根据主键提取认证用户
     *
     * @param $identifier
     * @return \auth\contract\Authenticatable|null
     */
    public function retrieveById($identifier): ?Authenticatable;

    /**
     * 根据 token 提取认证用户
     *
     * @param  \auth\AccessToken  $token
     * @return \auth\contract\Authenticatable|null
     */
    public function retrieveByToken(\auth\AccessToken $token): ?Authenticatable;

    /**
     * 根据账号信息从数据库中提取用户
     *
     * @param  array  $credentials
     * @return \auth\contract\Authenticatable|null
     */
    public function retrieveByCredentials(array $credentials): ?Authenticatable;

    /**
     * 核验用户凭证
     *
     * @param  \auth\contract\Authenticatable  $user
     * @param  array  $credentials
     * @return bool
     */
    public function validateCredentials(Authenticatable $user, array $credentials): bool;
}
